Skip to content

feat: Expose metrics API to Objective-C #7339

Closed
tustanivsky wants to merge 5 commits intomainfrom
ivan/metrics-api-objc
Closed

feat: Expose metrics API to Objective-C #7339
tustanivsky wants to merge 5 commits intomainfrom
ivan/metrics-api-objc

Conversation

@tustanivsky
Copy link
Copy Markdown
Collaborator

📜 Description

This PR introduces SentryMetrics wrapper class that bridges the Swift-only metrics API (count, distribution, gauge) to Objective-C.

This pattern was used because there is no way to make the underlying types @objc-compatible:

  • SentryUnit is a Swift enum with associated values
  • SentryAttributeValue is a Swift protocol
  • SentryMetricsApi is a generic struct which also cannot be `@objc

Even though the static type of SentrySDK.metrics changed from SentryMetricsApiProtocol to SentryMetrics, read access remains fully backward-compatible because SentryMetrics conforms to SentryMetricsApiProtocol, so existing Swift call sites and variables typed as the protocol continue to work.

The actual breaks would only be:

  • Assigning a custom conformer to the property: SentrySDK.metrics = MyCustomImpl()
  • Explicitly using the old concrete type: let m: SentryMetricsApi<...> = SentrySDK.metrics

However, neither of these look like supported use-cases.

💡 Motivation and Context

The Unreal Engine plugin uses sentry-cocoa internally via Objective-C which previously had no access to the metrics API. This change enables metrics calls from any Objective-C context by accepting String for units and [String: Any] for attributes converting them to the Swift-native types internally.

Related items:

💚 How did you test it?

Manually emitted counter, gauge, and distribution metrics in Unreal Engine using a patched version of the Cocoa SDK in the plugin.

📝 Checklist

You have to check all boxes before merging:

  • I added tests to verify the changes.
  • No new PII added or SDK only sends newly added PII if sendDefaultPII is enabled.
  • I updated the docs if needed.
  • I updated the wizard if needed.
  • Review from the native team if needed.
  • No breaking change or entry added to the changelog.
  • No breaking change for hybrid SDKs or communicated to hybrid SDKs.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Feb 2, 2026

Semver Impact of This PR

🟡 Minor (new features)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


New Features ✨

  • Expose metrics API to Objective-C by tustanivsky in #7339

Bug Fixes 🐛

  • In_foreground and is_active app context by philipphofmann in #7188

Internal Changes 🔧

  • ObjC Integration cleanup by itaybre in #7320

🤖 This preview updates automatically when you update the PR.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Feb 2, 2026

Messages
📖 Do not forget to update Sentry-docs with your feature once the pull request gets approved.

Generated by 🚫 dangerJS against 083ff1b

@codecov
Copy link
Copy Markdown

codecov bot commented Feb 2, 2026

Codecov Report

❌ Patch coverage is 44.11765% with 19 lines in your changes missing coverage. Please review.
✅ Project coverage is 84.857%. Comparing base (142ed2c) to head (083ff1b).
⚠️ Report is 1 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
...ces/Swift/Integrations/Metrics/SentryMetrics.swift 44.117% 19 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@              Coverage Diff              @@
##              main     #7339       +/-   ##
=============================================
- Coverage   85.182%   84.857%   -0.325%     
=============================================
  Files          475       471        -4     
  Lines        28560     28483       -77     
  Branches     12410     12299      -111     
=============================================
- Hits         24328     24170      -158     
- Misses        4185      4267       +82     
+ Partials        47        46        -1     
Files with missing lines Coverage Δ
Sources/Swift/Helper/SentrySDK.swift 84.259% <ø> (ø)
...ces/Swift/Integrations/Metrics/SentryMetrics.swift 44.117% <44.117%> (ø)

... and 27 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 142ed2c...083ff1b. Read the comment docs.

Copy link
Copy Markdown
Member

@philprime philprime left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am going to raise an internal discussion on this, because there might have been a miscommunication, so please hold back from further adapting this PR for now

@tustanivsky
Copy link
Copy Markdown
Collaborator Author

Closing this for now as the Metrics API is intended to remain a Swift-only interface.

@tustanivsky tustanivsky closed this Feb 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants